/**
 * TO BE DETERMINED
 */
package org.eichar.client;

import org.eichar.client.observer.AcceptObserver;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * The Quiz Tab.
 * <p>
 * Creates a panel consisting of Panel obtained from a {@link Question} and
 * "Accept", "Try Again" and "Next" buttons
 * </p>
 * 
 * @author Jesse
 */
public class Quiz {
    private final DataAccess dataAccess;

    private Widget widget;

    private Question question;

    private I18N i18n;

    public Quiz(DataAccess dataAccess, I18N i18n) {
        this.dataAccess = dataAccess;
        question = this.dataAccess.getQuestion();
        this.i18n = i18n;

        createPanel();
    }

    private void createPanel() {
        VerticalPanel panel = new VerticalPanel();
        panel.add(question.getPanel().getWidget());
        panel.setStyleName("white-background"); //$NON-NLS-1$

        LanguageConstants constants2 = i18n.getConstants();

        HorizontalPanel hPanel = new HorizontalPanel();

        Button accept = new Button(constants2.accept());
        hPanel.add(accept);

        Button next = new Button(constants2.next());
        hPanel.add(next);

        panel.add(hPanel);
        panel.setCellHorizontalAlignment(hPanel, HorizontalPanel.ALIGN_RIGHT);

        // create observers.
        new AcceptObserver(accept, question, next);

        panel.setCellHorizontalAlignment(hPanel, VerticalPanel.ALIGN_RIGHT);
        widget = panel;
    }

    public Widget getWidget() {
        return widget;
    }

}
